postgresql 12 TDE 源码最佳实践
所有操作跟 PostgreSQL 源码最佳实践 相同。
1 编译postgresql 软件包并安装到指定目录
su - postgres
cd /soft/
tar -zxf postgresql-*.tar.gz
cd /soft/postgresql-*/
./configure --prefix=/usr/local/pg12 --with-systemd --with-openssl --enable-debug --with-icu --enable-nls --with-zlib --with-libxml --with-perl --with-ldap --with-python
make -j 8
make install
Configure常用配置选项:
选项 | 说明 |
---|---|
prefix | 指定软件的安装路径 |
with-openssl | 对openssl进行扩展支持 |
with-python | 对python进行扩展支持 |
with-perl | 对perl进行扩展支持 |
with-libxml | 对xml进行扩展支持 |
--with-pgport | 数据库端口号 |
--with-tcl | 对C 语言扩展支持 |
--with-pam | 使用PAM(可插入身份验证模块)支持构建。 |
--with-libxml | 对 libxml2 扩展 |
--with-blocksize | 数据库块大小。 |
--with-llvm | 支持基于 LLVM 的 JIT 编译进行构建。 |
--with-ssl=openssl | 等同于 with-openssl |
--with-systemd | 使用linux 服务器管理 |
--with-zlib | |
--enable-nls | |
--with-icu | |
--enable-debug | |
--with-libxml | |
--with-uuid=e2fs |
--with-blocksize
•如果数据库需要经常做插入的操作,数据量增长非常快,尽量把此参数设大一点;
•经常做小数据查询、更新且内存不是非常大的时候可以设小一点,默认8K即可。
•生产环境不要加--enable-dtrace --enable-debug。
2 编译第三方插件并安装
Warning
要使用postgres 用户编译和安装。
cd contrib
make install
Note
gmake world包含了所有文档和所有contirb 。
3 创建数据库集簇
3.1 创建目录
postgres>
mkdir -p /usr/local/pgsql/data
3.2 创建秘钥
[postgres@node1 ~]$ vi provide_key.sh
#!/bin/sh
echo 882fb7c12e80280fd664c69d2d636913
[postgres@node1 ~]$ chmod +x provide_key.sh
3.3 初始化数据库集簇
postgres>
initdb -D $PGDATA -W --data-checksums -A scram-sha-256 -E UTF-8 -K /home/postgres/provide_key.sh
Warning
1、要想初始化集簇为英文,需要设置 LANG=en_US.UTF-8
。
2、更多关于Postgersql 能够初始化的字符集请见 PostgreSQL: Documentation: 15: 24.3. Character Set Support
3、复制时需要 data-cecksums 支持块校验。
3.4 启动数据库集簇
postgres>
pg_ctl start -D $PGDATA -l logfile start
3.5 创建新的数据库
postgres>
createdb testdb
3.6 登录数据库
psql testdb
4 查看是否使用TDE 加密
grep encryption_key $PGDATA/postgresql.conf
//屏幕输出:
encryption_key_command = '/home/postgres/provide_key.sh'
4.1 查看控制文件
pg_controldata
//屏幕输出:
... ...
Data encryption: on
Data encryption fingerprint: 740A905130FE614CE0BE36B612157A09
4.2 查看加密相关参数
SHOW data_encryption ;